package com.hfzy.ihk.facade.userCenter.enums;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hfzy.ihk.common.facade.CustomEnumType;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wws
 */


public enum UserType implements CustomEnumType{
    NOT_USE("N", "作废"),
    NORMAL("U", "正常");

    private String value;
    private String desc;
    private static Map<String, UserType> valueMap;
    private static Map<String, UserType> descMap;
    private static Map<String, UserType> nameMap;
    private static Map<String, String> kvMap;
    private static Map<String, String> kJsonMap;

    private UserType(String value, String desc) { this.value = value;
        this.desc = desc;
    }

    @Override
    public String getValue()
    {
        return this.value;
    }

    @Override
    public String getDesc()
    {
        return this.desc;
    }

    public static UserType fromValue(String name)
    {
        UserType ret = valueMap.get(name);
        if (ret != null) {
            return ret;
        }
        throw new IllegalArgumentException("No enum const " + UserType.class + "." + name);
    }

    public static UserType fromDesc(String desc) {
        UserType ret = descMap.get(desc);
        if (ret != null) {
            return ret;
        }
        throw new IllegalArgumentException("No enum const " + UserType.class + "." + desc);
    }

    public static Map<String, UserType> getDescMap()
    {
        return descMap;
    }

    public static Map<String, UserType> getKeyMap() {
        return nameMap;
    }

    public static Map<String, String> getKvMap()
    {
        return kvMap;
    }

    public static Map<String, String> getkJsonMap() {
        return kJsonMap;
    }

    @Override
    public String toString() {
        return kJsonMap.get(this.value);
    }

    static
    {
        valueMap = new HashMap();
        descMap = new HashMap();
        nameMap = new HashMap();
        kvMap = new HashMap();
        kJsonMap = new HashMap();

        for (UserType value : values()) {
            valueMap.put(value.getValue(), value);
            descMap.put(value.getDesc(), value);
            nameMap.put(value.name(), value);
            kvMap.put(value.getValue(), value.getDesc());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("key",value.getValue());
            jsonObject.put("value",value.getDesc());
            kJsonMap.put(value.getValue(), JSON.toJSONString(jsonObject));
        }
    }
}
